# -*- mode: python; coding: utf-8; -*-
##--------------------------------------------------------------------------##
##
## Copyright (C) 1998-2003 Markus Oberhumer <markus@oberhumer.com>
## Copyright (C) 2003 Mt. Hood Playing Card Co.
## Copyright (C) 2005-2010 Skomoroh <skomoroh@users.sourceforge.net>
## Copyright (C) 2010-2013 Jeremy Austin-Bardo <tjaustinbardo@gmail.com>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.
##
##--------------------------------------------------------------------------##
__docformat__ = 'restructuredtext en'
__all__ = []

from ... import formlib as layout
from ... import pilelib as stack
from ...gamelib import info as gi
from ...packlib import info as cs
from ...piles import dashavatara as dstack
from .. import picturegallery

GT, SL = gi.GT, gi.SL
Wrap = stack.StackWrapper


class Dashavatara(cs.Dashavatara_Deck, picturegallery.PictureGallery):
    """
    Arrange cards on tableaux within a turn.

    Layout
      - tableau [30 over 3 row NW, vert offset]
      - row [10 horz SW, vert offset]
      - talon [1 SE, no offset]
      - reserve [3 vert E, no offset]

    :CVariables:
      _tableaux_ : pysollib.stack.Stack
        .. pysollib.games.picturegallery.TableauStack (max_cards=4, dir=3,
          base_rank=FOUR, max_accept=1),
          pysollib.games.picturegallery.TableauStack (max_cards=4, dir=3,
          base_rank=THREE, max_accept=1),
          pysollib.games.picturegallery.TableauStack (max_cards=4, dir=3,
          base_rank=TWO, max_accept=1)
        Init 1 card. Build in rank by 3. Play top. Base ace N; two center;
        three S.

    _row_ : pysollib.stack.Stack
      .. pysollib.games.picturegallery.RowStack
      Init 1 card. Gap deal 1 card from talon. Play top.

    _talon_ : pysollib.stack.Stack
      .. pysollib.stack.DealRowTalon
      Deal 1 card per row. No redeals.

    _reserve_ : pysollib.stack.Stack
      .. pysollib.stack.ReserveStack
      Build any while talon has cards. Play top. Max 1 card.

    _hint_ : pysollib.hint.AbstarctHint
      .. pysollib.games.picturegallery.Hint

    note::
      ⟪highlight_play⟫ disabled.
    """
    __info__ = dict(id=15422, name='Dashavatara',
                    category=cs.TYPE_DASHAVATARA_GANJIFA,
                    game_type=GT.ONE_DECK, decks=1, skill_level=SL.BALANCED,
                    version='0.50fc')
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70

    _tableaux_ = (Wrap(picturegallery.TableauStack, max_cards=4, dir=3,
                       base_rank=cs.ACE, max_accept=1),
                  Wrap(picturegallery.TableauStack, max_cards=4, dir=3,
                       base_rank=cs.TWO, max_accept=1),
                  Wrap(picturegallery.TableauStack, max_cards=4, dir=3,
                       base_rank=cs.THREE, max_accept=1),)
    _reserve_ = dstack.Dashavatara_ReserveStack

    def _create_game(self, **kw):
        """
        Create game format.

        Overide pile placements based on current attributes.

        .. \_create_game() -> Layout
        """
        l, s = layout.Layout(self), self.s
        dy = l._get_stack_height(4, l.YS)
        self.table_size = (l.XM + (l.NSUITS + 2) * l.XS,
                           2 * l.YM + 3 * dy + l._get_stack_height(9, l.YS),)
        s['tableaux'] = []
        for y, _tableau_ in zip(l.col_iter(l,YM, 3, dy), self._tableaux_):
            for x in l.row_iter(l.XM, npiles=l.NSUITS):
                s['tableaux'].append(_tableau_(x, y, game=self,
                                               offset=(0, l.YOFFSET)))
            s['reserves'].append(self._reserve_(x + l.XS, y, game=self))
        y += l.YM
        s['rows'] = [self._row_(x, y, game=self)
                        for x in l.row_iter(l.XM, npiles=l.NSUITS)]
        x, y = self.width - 3 * l.HXS, self.height - l.YS
        s['talon'] = self._talon_(x, y, game=self)
        l.set_ncards_text(s['talon'], 'se')
        if self._waste_ is not None:
            y -= l.YS
            s['wastes'].append(self._waste_(x, y, game=self))
            l.set_ncards_text(s['wastes'][-1], 'se')
        self._set_region(s['tableaux'], l._region(w=x - l.HCW, h=y - l.CH))
        self.defaultStackGroups()
        self.sg['openstacks'] += s['tableaux']
        self.sg['dropstacks'] += s['tableaux']
        self.sg['reservestacks'] = s['rows']


PROVIDES = [Dashavatara]